#郑文超

import time,os
from common.zwc_login import Login
from testcase.financial_approval import financial_flow
from faker import Factory
from testcase.jiemi import quiry
from utils.utility import Utility
from common.report_generate import Report
from selenium.webdriver.support.select import Select

class Financial_f:

    def __init__(self,username):
        self.driver= financial_flow(username,"财务管理","预支结算")
        self.st = self.driver
        self.connet_sql = Utility()
        self.write_sql = Report()

    def add_pool(self):
        # 解除二级密码
        self.st.driver.find_element_by_id('btn-decrypt').click()
        # time.sleep(1)
        self.st.driver.find_element_by_name('secondPass').send_keys('Woniu123')
        self.st.driver.find_element_by_xpath('//*[@id="secondPass-modal"]/div/div/div[3]/button').click()
        time.sleep(1)
        try:
            self.st.driver.find_element_by_xpath('/html/body/div[9]/div/div/div[3]/button').click()
            print('解密失败')
        except:
            print('解密成功')

    #点击展开按钮，是否显示详细信息
    def test_case1(self,s_num,title,caseid):
        self.st.open().click()
        try:
            self.st.driver.find_element_by_xpath("//*[@id='advance-table']/tbody/tr[2]/td")
            print("测试通过")
            self.write_sql.write_report('3.5', '财务流水', 'GUI自动化测试',title, caseid, '成功', '无', "无")
        except:
            print("测试失败")
            img = self.st.screenshot()
            self.write_sql.write_report('3.5', '财务流水', 'GUI自动化测试', title, caseid, '失败', '无', img)

    #点击添加明细
    def test_case2(self,s_num,title,caseid):
        self.st.driver.find_element_by_xpath("//*[@id='advance-table']/tbody/tr[1]/td[11]/button").click()
        wd1 = self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[1]/div[1]/select")
        self.st.random_select(wd1, s_num[0])
        wd2 = self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[1]/div[2]/select")
        self.st.random_select(wd2, s_num[1])
        wd3 = self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[3]/div[1]/input").send_keys(s_num[2])
        self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[3]/div[2]/input").send_keys(s_num[3])
        self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[4]/div[1]/input").click()
        self.st.driver.find_element_by_xpath("/html/body/div[10]/div[3]/table/tfoot/tr[1]/th").click()
        wd4 = self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[4]/div[2]/select")
        self.st.random_select(wd4, s_num[5])
        self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[5]/div/input").send_keys(s_num[6])
        self.st.driver.find_element_by_xpath("//*[@id='addDetail-form']/div/div[6]/div/textarea").send_keys(s_num[7])
        self.st.driver.find_element_by_xpath("//*[@id='add-detail']/div/div/div[2]/button").click()
        result = self.st.driver.find_element_by_xpath("/html/body/div[12]/div/div/div[2]/div").get_attribute('textContent')
        if result == "新增成功":
            self.write_sql.write_report('3.5', '财务流水', 'GUI自动化测试', title, caseid, '成功', '无', "无")
            print("保存成功")
        else:
            print('保存失败')
            img = self.st.screenshot()
            self.write_sql.write_report('3.5', '财务流水', 'GUI自动化测试', title, caseid, '失败', '无', img)
        time.sleep(1)
        self.st.driver.find_element_by_xpath("/html/body/div[12]/div/div/div[3]/button").click()
        self.st.driver.close()

    ##验证查询结果与查询条件是否一致，例如查询区域：成都
    def test_case3(self,s_num,title,caseid):
        flag = True
        wd = self.st.driver.find_element_by_name("regionId")
        self.st.random_select(wd,s_num[0])

        result = self.st.driver.find_element_by_xpath("//*[@id='advance-table']/tbody/tr[1]/td[2]").text
        print(result)
        if s_num[0] == result:
            self.write_sql.write_report('3.5', '财务流水', 'GUI自动化测试',title, caseid, '成功', '无', "无")
        else:
            img = self.st.screenshot()
            self.write_sql.write_report('3.5', '财务流水', 'GUI自动化测试', title, caseid, '失败', '无', img)
        self.st.driver.close()
if __name__ == '__main__':
    start = Financial_f("超级管理员")
    start.add_pool()